<?php 
namespace Common\Model;
use Think\Model;
class UserLogModel extends Model{
	
	/**
	 * 写日志
	 * @param unknown $uid
	 * @param unknown $action
	 * @param unknown $info
	 * @return Ambigous <\Think\mixed, boolean, unknown, string>
	 */
	public function _add($uid,$action,$info){
		
		$data['uid'] = $uid;
		$data['action'] = $action;
		$data['info'] = $info;
		$data['ip'] = $this->getRealIp();
		$data['client'] = $_SERVER['HTTP_USER_AGENT'];
		$data['create_time'] = Date("Y-m-d H:i:s");
		
		return $this->add($data); //写入数据
		
	}
	
	public function getRealIp(){
		$ip=false;
		if(!empty($_SERVER["HTTP_CLIENT_IP"])){
			$ip = $_SERVER["HTTP_CLIENT_IP"];
		}
		if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
			$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
			if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
			for ($i = 0; $i < count($ips); $i++) {
				if (!eregi ("^(10│172.16│192.168).", $ips[$i])) {
					$ip = $ips[$i];
					break;
				}
			}
		}
		return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
	}
}
?>